package com.jy.wms.controller;

import com.joyi.gate.comm.SessionInfo;
import com.joyi.gate.safety.vo.UserInfo;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.*;
import com.jy.wms.pojo.WmsQualityTesting;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.jy.wms.pojo.WmsQualityTestingDetailed;
import com.jy.wms.service.WmsQualityTestingDetailedService;
import javax.servlet.http.HttpSession;
import com.github.pagehelper.Page;

import java.util.List;
import com.jy.wms.common.UUIDUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @ClassName: WmsQualityTestingDetailedController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author LH
 * @Date Fri Nov 03 15:50:33 GMT+08:00 2017
 */
@RestController
@RequestMapping("/wmsqualitytestingdetailed")
@Api(value = "/wmsqualitytestingdetailed", description = "关于质检规则明细操作")

public class  WmsQualityTestingDetailedController extends BaseController<WmsQualityTestingDetailedService,WmsQualityTestingDetailed> {

    @PostMapping(value = "add")
    @ApiOperation(value = "编辑信息",response = JSONObject.class, notes = "增加质检规则明细信息")
    public @ResponseBody JSONObject editWmsQualityTesting(@RequestBody WmsQualityTestingDetailed entity, HttpSession session) {
        UserInfo userinfo = (UserInfo) session.getAttribute(SessionInfo.USER_INFO);//用户信息
        String ckid = String.valueOf(userinfo.getUser().getOrgId().get(0));//仓库id
        entity.setCkid(ckid);
        entity.setId(UUIDUtils.uuid());
        try {
            Integer flag=baseService.baseInsertSelective(entity);
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(), "质检规则明细添加成功", "", JSONObject.fromObject(entity).toString());
        } catch (ServiceException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "质检规则明细添加失败", e.getMessage(), "");
        } catch (SucessException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(), "质检规则明细添加成功", "", JSONObject.fromObject(entity).toString());
        }catch (Exception e){
            baseService.deleteById(entity.getId());
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "质检规则明细添加失败", e.getMessage(), "");
        }

    }


    @ApiOperation(value = "编辑时查找明细集合", response = JSONObject.class, notes = "编辑时查找明细集合,sszjgzid:质检规则id")
    @GetMapping(value = "getDetailList/{sszjgzid}")
    public @ResponseBody
    JSONArray getDetailList(@PathVariable String sszjgzid) {
        JSONArray jsonArray=null;
        try {
            jsonArray=baseService.getDetailList(sszjgzid);
        } catch (ServiceException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonArray;
    }

    @ApiOperation(value = "质检规则明细删除", response = JSONObject.class, notes = "查询输入</br>{\"ids\":\"明细id集合\"}")
    @PostMapping(value = "delete")
    public @ResponseBody
    JSONObject delete(@RequestBody SetAndModifyModel setModel, HttpSession session) {
        UserInfo userinfo = (UserInfo) session.getAttribute(SessionInfo.USER_INFO);//用户信息
        try {
            baseService.baseDeleteByPrimaryKey(setModel.getIds(),setModel.getId());
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(), "质检规则明细删除成功", "", "");
        } catch (SucessException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_top.getType(), ReturnType.success.toString(), "质检规则明细删除成功", e.getMessage(), "");
        } catch (ServiceException e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "质检规则明细删除失败", e.getMessage(), "");
        } catch (Exception e) {
            e.printStackTrace();
            return SetStatus.setFunctionType(ReturnType.messageType_right.getType(), ReturnType.error.toString(), "质检规则明细删除失败", e.getMessage(), "");
        }
    }


 /*   @PostMapping(value = "edit")
    @ApiOperation(value = "编辑信息",response = JSONObject.class, notes = "编辑信息")
    public @ResponseBody JsonResult editWmsQualityTestingDetailed(@RequestBody WmsQualityTestingDetailed entity) {
        Integer flag=baseService.baseUpdateByPrimaryKeySelective(entity);
        return renderSuccess("修改成功");
    }*/
}
